package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.pagequery.NursingProjectPageQueryParam;
import com.zzyl.service.NursingProjectService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.NursingProjectVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@RequiredArgsConstructor
public class NursingProjectServiceImpl implements NursingProjectService {

    private final NursingProjectMapper nursingProjectMapper;

    /**
     * 护理分页查询
     * @param nursingProjectPageQueryParam
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> pageInfo(NursingProjectPageQueryParam nursingProjectPageQueryParam) {

        //完成分页操作
        PageHelper.startPage(nursingProjectPageQueryParam.getPage(), nursingProjectPageQueryParam.getPageSize());

        //查询
        Page<NursingProject> nursingProjects = nursingProjectMapper.nursingProjectPageInfo(nursingProjectPageQueryParam);

        //封装分页参数
        return PageResponse.of(nursingProjects, NursingProjectVo.class);
    }

    /**
     * 添加护理项目
     * @param nursingProjectDto
     */
    @Override
    public void addNursingProject(NursingProjectDto nursingProjectDto) {
        //拷贝属性交给实体
        NursingProject nursingProject = BeanUtil.copyProperties(nursingProjectDto, NursingProject.class);
        //插入
        nursingProject.setCreateBy(UserThreadLocal.getUserId());
        nursingProject.setUpdateBy(UserThreadLocal.getUserId());
        nursingProjectMapper.insertNursingProject(nursingProject);
    }

    /**
     * 根据id查询护理项目
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getById(Long id) {
        return  nursingProjectMapper.selectNursingProjectById(id);
    }

    /**
     * 修改护理项目
     * @param nursingProjectDto
     */
    @Override
    public void updateNursingProject(NursingProjectDto nursingProjectDto) {
        //拷贝属性交给实体
        NursingProject nursingProject = BeanUtil.copyProperties(nursingProjectDto, NursingProject.class);
        //执行更新操作
        nursingProject.setUpdateBy(UserThreadLocal.getUserId());
        nursingProjectMapper.updateNursingProject(nursingProject);
    }

 /*   *//**
     * 修改护理项目状态
     * @param id
     * @param status
     *//*
    @Override
    public void updateNursingProjectStatus(Long id, Integer status) {
        NursingProject nursingProject = new NursingProject();
        nursingProject.setId(id);
        nursingProject.setStatus(status);
        nursingProjectMapper.updateNursingProject(nursingProject);
    }

    *//**
     *根据id删除护理项目
     * @param id
     *//*
    @Override
    public void deleteById(Long id) {
        nursingProjectMapper.deleteById(id);
    }

    *//**
     * 查询所有护理项目
     * @return
     *//*
    @Override
    public List<NursingProjectVo> getAll() {
        return nursingProjectMapper.selectAll();
    }*/
}
